<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>28.购物车汇总与获取最贵商品</title>
</head>

<body>
  <script>
    let cart = [
      { name: "iphone", price: 12000 },
      { name: "imac", price: 25000 },
      { name: "ipad", price: 3600 }
    ];
    function maxPrice(goods){
      return goods.reduce(function (pre,cur){
        return pre.price>cur.price?pre: cur;
      });
    }
    function sum(goods){
      return goods.reduce(
        (total, cur)=> total+= cur.price,0); 
    }
    console.log(maxPrice(cart));
    console.log(sum(cart));
  </script>
</body>

</html>